<template>
  <div>
    <div class="clearfix">
      <el-menu
        :default-active="activeIndex"
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
        background-color="#2a2d2f"
        text-color="#fff"
        active-text-color="#ffd04b"
        style="border-bottom: none;display: inline-block;float: left">
        <el-menu-item index="1">待审批</el-menu-item>
        <el-menu-item index="2">已审批</el-menu-item>
      </el-menu>
      <div class="clearfix">
        <el-input
          class="searchDepartment"
          placeholder="输入审批编号"
          prefix-icon="el-icon-search"
          v-model="search"
          style="margin: 15px 15px;width: 250px;float: right"
          @input="SearchExamine">
        </el-input>
      </div>
    </div>
    <div style="padding:15px;">
      <div style="background-color: white;">

        <div style="margin: 0 15px;">
          <el-table
            :data="ExamineTable"
            stripe
            style="width: 100%;padding-top: 20px;"
            :header-cell-style="{background:'#eef1f6',color:'#606266'}"
            @row-click="openExamine">
            <el-table-column
              prop="number"
              label="审批编号">
            </el-table-column>
            <el-table-column
              prop="apply"
              label="申请人">
              <template slot-scope="scope">
                <el-avatar style="float:left; margin-top:3px;" size="small" :src="scope.row.circleUrl"></el-avatar>
                <span style="float:left;margin-left: 5px;margin-top: 8px">{{ scope.row.apply }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="date"
              label="申请时间">
            </el-table-column>
            <el-table-column
              prop="status"
              label="审批状态">
              <template slot-scope="scope">
                <el-tag type="warning" v-show="scope.row.status == '待审批'">待审批</el-tag>
                <el-tag type="info" v-show="scope.row.status == '已撤销'">已撤销</el-tag>
                <el-tag type="danger" v-show="scope.row.status == '已回拒'">已回拒</el-tag>
                <el-tag type="success" v-show="scope.row.status == '已通过'">已通过</el-tag>
              </template>
            </el-table-column>
          </el-table>
          <div style="margin-top: 10px;text-align: center">
            <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[5, 6, 7, 8]"
              :page-size="PageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  const axios = require('axios');
  export default {
    name: "applyExamine",
    data() {
      return {
        activeIndex : '1',
        //分页数据
        currentPage: 1,
        total: 0,
        PageSize: 5,
        currentTable: 1,

        search: '',

        ExamineTable: [],
      }
    },
    created() {
      axios.post("/findMyExamine",{"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
        this.ExamineTable = res.data.list;
        this.total = res.data.total;
      })
    },
    methods: {
      handleSelect(key) {
        if(key == 1){
          axios.post('/findMyExamine', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.ExamineTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 1;
          })
        }else{
          axios.post('/findMyExamineComplete', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.ExamineTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 2;
          })
        }
      },
      handleSizeChange(val) {
        this.PageSize = val;
        if(this.currentTable = 1){
          axios.post('/findMyExamine', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.ExamineTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 1;
          })
        }else if(this.currentTable = 2){
          axios.post('/findMyExamineComplete', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.ExamineTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 2;
          })
        }else{
          axios.post('/SearchMyExamine', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id"),"content":this.search}).then(res => {
            this.ExamineTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 3;
          })
        }
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        if(this.currentTable = 1){
          axios.post('/findMyExamine', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.ExamineTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 1;
          })
        }else if(this.currentTable = 2){
          axios.post('/findMyExamineComplete', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id")}).then(res => {
            this.ExamineTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 2;
          })
        }else{
          axios.post('/SearchMyExamine', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id"),"content":this.search}).then(res => {
            this.ExamineTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 3;
          })
        }
      },

      SearchExamine(){
        axios.post('/SearchMyExamine', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":window.localStorage.getItem("id"),"content":this.search}).then(res => {
          this.ExamineTable = res.data.list;
          this.total = res.data.total;
          this.currentPage = 1;
          this.currentTable = 3;
        })
      },

      openExamine(row){
        this.$emit("openExamine",row.id);
      }
    }
  }
</script>

<style scoped>

</style>
